


require 'player'


local function new()
    return {
            players = {},
            names = {}
    }
end


local function free_player(self, linefd)
    players = self.players
    player = players[linefd]
    players[linefd] = nil
    PLAYER.free(player)
end
local function cget_player(self, linefd)
    players = self.players
    player = players[linefd]
    if player == nil then
        player = PLAYER.new()
        player.linefd = linefd;
        players[linefd] = player
    end

    return player
end

local function find_player(self, linefd)
    players = self.players
    return players[linefd]
end


local function rename(self, player, id)
    names = self.names
    names[id] = player
end

local function lookup(self, id)
    names = self.names
    return names[id]
end



PLAYERMAP = {
    new = new,
    cget_player = cget_player,
    find_player = find_player,
    free_player = free_player,
    rename = rename,
    lookup = lookup
}


return PLAYERMAP
